const { localStorage } = cc.sys

export default class LocalStorageManager {
    public static set(key: string, value: any) {
        localStorage.setItem(key, JSON.stringify(value))
    }

    public static has(key: string) {
        return localStorage.getItem(key) == null
    }

    public static get(key: string, defaultValue: any = null) {
        let value = localStorage.getItem(key)
        if (value == null && defaultValue != null) {
            return defaultValue
        }

        return JSON.parse(value)
    }

    public static remove(key: string) {
        localStorage.removeItem(key)
    }

    public static clear() {
        localStorage.clear()
    }
}
